package com.wing.bill.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wing.bill.model.entity.WarehouseBillDetail;
import com.wing.bill.model.entity.WarehouseProcessBillDetail;
import com.wing.bill.model.response.WarehouseBillDetailVO;
import com.wing.bill.model.response.WarehouseProcessBillDetailVO;
import com.wing.bill.model.response.WarehouseProcessBillVO;
import com.wing.bill.service.WarehouseBillDetailService;
import com.wing.bill.service.WarehouseProcessBillDetailService;
import com.wing.common.constant.SecurityConstants;
import com.wing.common.utils.JsonResult;
import com.wing.common.utils.PageResult;
import com.wing.web.utils.JwtUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Api(value = "生产加工账单明细管理", tags = "#/warehouse/bill/warehouseProcessBillDetail")
@RestController("WarehouseProcessBillDetailController")
@RequestMapping("/warehouse/admin/bill/processBillDetail")
@RequiredArgsConstructor
public class WarehouseProcessBillDetailController {

    @Autowired
    private WarehouseProcessBillDetailService warehouseProcessBillDetailService;


    @ApiOperation(value = "查看账单", notes = "搜索")
    @GetMapping("/list")
    public PageResult<Page<WarehouseProcessBillDetailVO>> list(
            @RequestParam(value = "page", defaultValue = "1", required = false) Integer page
            ,@RequestParam(value = "limit", defaultValue = "10", required = false) Integer limit
            ,@RequestParam(value = "sort", defaultValue = "create_time", required = false) String sort
            ,@RequestParam(value = "order", defaultValue = "asc", required = false) String order
            ,String warehouseCustomerId
    ){

        Page<WarehouseProcessBillDetail> pg = new Page<>(page, limit);
        Map paramMap=new HashMap();
        //判断客户端，如果是会员端，则需要添加对应的部门信息作为查询条件
        if(JwtUtils.getClientId().equals(SecurityConstants.WAREHOUSE_CLIENT_ID)){
            paramMap.put("customerId",JwtUtils.getDepartmentId());
        }else{
            if(!StringUtils.isEmpty(warehouseCustomerId)){
                paramMap.put("customerId",warehouseCustomerId);
            }
        }
        //搜索
        return warehouseProcessBillDetailService.pageList4app(pg,paramMap);
    }

    @ApiOperation(value = "查询账单详情", notes = "查询")
    @GetMapping ("/selectBillDetail")
    public JsonResult<WarehouseProcessBillDetailVO> selectBillDetail(@RequestParam String id){
        WarehouseProcessBillDetailVO warehouseProcessBillDetailVO = warehouseProcessBillDetailService.selectBillDetail(id);
        return JsonResult.success(warehouseProcessBillDetailVO);
    }
}
